% Data for italy-ROW case
% clear all
% close all
% setup_workspace
[num,txt,raw] = xlsread('ITA_ROW.xlsx');

% data are from 1974 to 2019Q4 but missing data for hours for ROW from
% 2016Q4
% with interest rate, data need to start fromm 1979Q2 (Ts=22)

% order of variables

% 1 Year
% 2 Quarter
% 3 YQ
% 4 gr RGDP ITA
% 5 gr PGDP ITA
% 6 gr RCon ITA
% 7 gr RInv ITA
% 8 gr Price of imports ITA
% 9 gr Price of Exports ITA
% 10 gr Hours ITA
% 11 gr TFP (annual - Fernald US)  
% 12 NX/Y ITA
% 13 REER ITA
% 14 gr RGDP ROW
% 15 gr PGDP ROW
% 16 gr Rcon ROW
% 17 gr RInv ROW
% 18 gr Price of imports ROW
% 19 gr Price of exports ROW
% 20 gr Hours ROW
% 21 ITA Interest Rate 
% 22 ROW Interest Rate (no data using all 13 countries available)
% 23 ROW Interest Rate starting from 1974 (adjusted weights for missing)
% 24 ITA 5 year yield
% 25 ITA 10 yeard yield
% 26 ROW 5 year yield
% 27 ROW 10 year yield
% 28 ITA spread
% 29 ROW spread
% 30 ITA real exports
% 31 ITA real imports
% 32 gr of TFP ROW
% 33 gr of TFP ITA we constructed
% 34 gr of TFP ROW adjusted 
% 35 gr of TFP ITA adjusted 
% 36 Global factor from Helene Ray Restud paper
% 37 Commodity price weigh by export shares of commodity
% 38 4q ahead annual growth rate of output 
% 39 4q ahead annual growth rate of consumption
% 40 constructed real exchange rate (average of quarter)
% 41 End of period short term rate ITA (3 month yield)
% 42 End of period short term rate ROW
% 43 Inflation rate CPI ITA
% 44 Inflation rate CPI ROW
% 45 End of period constructed real exchange rate
% 46 End of period constructed RER using BIS (CORRECT)
% 47 Average daily constructed RER using BIS (CORRECT)
% 48 haver daily constructed rer
% 49 new EOP constructed RER using BIS (multiplication)
% 50 new average constructed rer using BIS (multiplication)
% 51 haver rer
% 52 realized vix
% 53 price index for energy
% 54 price index for non energy 
% 55 price index for agriculture
% 56 price index for precious metals
% 57 N export/ gdp
% 58 N imports/ gdp
% 59 Nominal exchange rate (End of period constructed NER - counterpart to 49)
% 60 real stock returns 
% 61 real trade balance
% 62 real trade balance/GDP
% 63 Terms of trade

[num1,txt1,raw1]=xlsread('spread.xlsx',2); % spread data
num1=num1(1:end-2,:); % 1974Q1 to 2019Q4 

Ts=1; 
Tstfp=2; %1974Q1 
% Ts=20; % 1978Q4
% Ts=22; % 1979Q2
Te=172; % 2016Q4

% [num2,txt2,raw2]=xlsread('forecast.xlsx'); % forecast data 
[num3,txt3,raw3]=xlsread('data_CCI.xlsx'); % consumer confidence data 

% Ts1=64; %1989Q4 to do with forecast
Ts_f=1; %1989Q4
Te_f=109; % 2016Q4

num=num(Ts:Te,:);
num1=num1(Ts:Te,:);
num3=num3(Ts:Te,:); 


% accumulate to log level for US and ROW
usdata_gr=num(:,[4 6 7 8 9 10 43]);
rowdata_gr=num(:,[14 16 17 18 19 20 44]);

usdata=cumsum(usdata_gr);
rowdata=cumsum(rowdata_gr);

% accumulate to log level for US real exports and real imports
usdata_gr1=num(:,[30 31]);
usdata1=cumsum(usdata_gr1);
logtfp_row=cumsum(num(Tstfp:end,32));
logtfp_usa=cumsum(num(Tstfp:end,33)); % our constructed TFP
logtfpua_usa=cumsum(num(Tstfp:end,35));
logtfpua_row=cumsum(num(Tstfp:end,34));

logtfp_usa=[NaN(Tstfp-Ts,1); logtfp_usa];
logtfp_row=[NaN(Tstfp-Ts,1); logtfp_row];

% labor productivity
lp_us=usdata(:,1)-usdata(:,6);
lp_row=rowdata(:,1)-rowdata(:,6);

% Interest Rate
intratediff=(num(:,21)-num(:,23))/100/4; % i-i_row
intratediff1=(num(:,21)-num(:,23))/100/4; % i-i_row from 1974
intratediff5=(num(:,24)-num(:,26))/100/4; % i-i_row 5 year
intratediff10=(num(:,25)-num(:,27))/100/4; % i-i_row 10 year
intratediffnew=(num(:,41)-num(:,42))/100/4; % i-i_row EOP

% dRER
dRER=log(num(:,49))-lagmatrix(log(num(:,49)),1);
dRER(1)=NaN;

% spread
% spread=num1(:,3)/100/4 ; % us spread
spread=(num(:,28)-num(:,29))/100/4 ; % us - row spread
GF=num(:,36);
X=log(num(:,37));

data1=[usdata(:,1)-rowdata(:,1) ... % y-y_row
    usdata(:,2)-rowdata(:,2) ... % c-c_row
    usdata(:,6)-rowdata(:,6) ... % h-h_row
    num(:,43) - num(:,44) ... % pi-pi_row
    usdata(:,3)-rowdata(:,3) ... % inv - inv_row
    num(:,12) ... % nxy
    log(num(:,49))... % REER
    intratediffnew ...  % i-i_row
    ]; 

db.data1=data1';
db.data_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate'};

data1_tfp=[data1 ...
        logtfp_usa-logtfp_row ... % fernald tfp - row tfp    
        ];
 db.data1_tfp=cutnan2(data1_tfp)';
 db.data_tfp_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate','TFP'};


dataREER=[usdata(:,1)-rowdata(:,1) ... % y-y_row
    usdata(:,2)-rowdata(:,2) ... % c-c_row
    usdata(:,6)-rowdata(:,6) ... % h-h_row
    num(:,43) - num(:,44) ... % pi-pi_row
    usdata(:,3)-rowdata(:,3) ... % inv - inv_row
    num(:,12) ... % nxy
    log(num(:,13))... % REER
    intratediffnew];  % i-i_row

db.dataREER=dataREER';

dataNER=[usdata(:,1)-rowdata(:,1) ... % y-y_row
    usdata(:,2)-rowdata(:,2) ... % c-c_row
    usdata(:,6)-rowdata(:,6) ... % h-h_row
    num(:,43) - num(:,44) ... % pi-pi_row
    usdata(:,3)-rowdata(:,3) ... % inv - inv_row
    num(:,12) ... % nxy
    log(num(:,59))... % NER
    intratediffnew ...  % i-i_row
    ]; 

db.dataNER=dataNER';
db.dataNER_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','NER','Interest Rate'};
                      
data_dRER=[usdata(:,1)-rowdata(:,1) ... % y-y_row
    usdata(:,2)-rowdata(:,2) ... % c-c_row
    usdata(:,6)-rowdata(:,6) ... % h-h_row
    num(:,43) - num(:,44) ... % pi-pi_row
    usdata(:,3)-rowdata(:,3) ... % inv - inv_row
    num(:,12) ... % nxy
    dRER ... % REER
    intratediffnew];  % i-i_row

db.data_dRER=cutnan2(data_dRER)';
db.data_dRER_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','dRER','Interest Rate'};

 data_rtby=[data1 ...
        num(:,62)]; 
db.data_rtby=cutnan2(data_rtby)'; 
db.data_rtby_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate','Real TBY'};
 data_tot=[data1 ...
        num(:,63)]; 
db.data_tot=cutnan2(data_tot)'; 
db.data_tot_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate','TOT'};

% wedge
                      
data_f=[data1 ...
        num(:,38)/400]; 
db.data_f=cutnan2(data_f)'; 
db.data_f_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate','Forecast'};
data_consconf=[data1 ...
                log(num3(:,8))];
db.data_consconf=cutnan2(data_consconf)'; 
db.data_consconf_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate','Consumer Confidence'};

data_spread=[data1 ...
                spread ]; % spread
db.data_spread_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate','Spread'};
data_spread=cutnan2(data_spread);
db.data_spread=data_spread'; % transpose

data_GF=[data1 ...
            GF];
data_GF=cutnan2(data_GF);
db.data_GF=data_GF';
db.data_GF_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate','Global Factor'};

data_commodity=[data1 ...
            X];
data_commodity=cutnan2(data_commodity);
db.data_commodity=data_commodity';
db.data_commodity_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate','Commodity Price'};

data_vix=[data1 ...
            num(:,52)];
        data_vix=cutnan2(data_vix);
        db.data_vix=data_vix';
        db.data_vix_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate','VIX'};
data_stock=[data1 ...
            num(:,60)];
        data_stock=cutnan2(data_stock);
        db.data_stock=data_stock';
        db.data_stock_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate','Stock returns'};

 % with P/P*
data_p=[usdata(:,1)-rowdata(:,1) ... % y-y_row
    usdata(:,2)-rowdata(:,2) ... % c-c_row
    usdata(:,6)-rowdata(:,6) ... % h-h_row
    usdata(:,7)-rowdata(:,7) ... % log(P)-log(P*)
    usdata(:,3)-rowdata(:,3) ... % inv - inv_row
    num(:,12) ... % nxy
    log(num(:,49))... % REER
    intratediffnew];  % i-i_row
db.data_p=data_p';
db.data_p_name={'Output','Consumption','Hours Worked',...
                          'CPI','Investment','NXY','REER','Interest Rate'};

% with exports and imports
data_expimp=[usdata(:,1)-rowdata(:,1) ... % y-y_row
    usdata(:,2)-rowdata(:,2) ... % c-c_row
    usdata(:,6)-rowdata(:,6) ... % h-h_row
    num(:,43) - num(:,44) ... % pi-pi_row
    usdata(:,3)-rowdata(:,3) ... % inv - inv_row
    log(num(:,49))... % REER
    intratediffnew ...  % i-i_row
    usdata1(:,1) ... % real exports
    usdata1(:,2)];  % real imports
db.data_expimp_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','REER','Interest Rate', 'Exports','Imports'};
db.data_expimp=data_expimp'; % transpose
    
data_yield5=[data1 ...   
    intratediff5];  % i-i_row  5 year
data_yield5=cutnan2(data_yield5);
db.data_yield5=data_yield5'; % transpose
db.data_yield5_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','interest rate','5 year Yield'};

data_yield10=[data1 ...
    intratediff10];  % i-i_row  10 year
data_yield10=cutnan2(data_yield10);
db.data_yield10=data_yield10'; % transpose
db.data_yield10_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','interest rate','10 year yield'};

                      
% individual country data
data_absolute=[usdata(:,1) ... % y
    usdata(:,2) ... % c
    usdata(:,6) ... % h
    num(:,43) ... % pi
    num(:,12) ... % nxy
    log(num(:,49))... % REER
    num(:,41)/400 ...  % i
    logtfp_usa ... US TFP
    rowdata(:,1) ... % y_row
    rowdata(:,2) ... % c_row
    rowdata(:,6) ... % h_row
    num(:,44) ... % pi_row
    num(:,42)/400 ... % i_row
    logtfp_usa ... % constructed US
    logtfp_row ... % row
    usdata(:,3) ... % i
    rowdata(:,3) ... % investment
    (num(:,28))/400 ... % us spread
    (num(:,29))/100/4 ...  %  row spread
    num(:,52) ... % vix
    num(:,57) ... % export/gdp
    num(:,58) ... % import/gdp
    ];
db.data_absolute_name={'US Output','US Consumption','US Hours Worked',...
                          'US Inflation','US NXY','US REER','US interest rate', 'US TFP', ...
                          'ROW Output','ROW Consumption','ROW Hours', ...
                          'ROW Inflation','ROW Interest rate', 'Our US TFP','Our ROW TFP','US Inv','ROW Inv',...
                          'US spread','ROW spread','VIX','Exports/GDP','Imports/GDP'};
                      
db.data_absolute=data_absolute'; % transpose

data_pcom=[data1 ...
        log(num(:,53)) ...
        log(num(:,54)) ...
        log(num(:,55)) ...
        log(num(:,56))];
    
        
 db.data_pcom=data_pcom';
 db.data_pcom_name={'Output','Consumption','Hours Worked',...
                          'Inflation','Investment','NXY','REER','Interest Rate','energy price','non energy price', ...
                          'agriculture price','metal price'};



  %% subperiod
Tbreak=133;
Tbreak_GF=109;


db.data1_sub1=db.data1(:,Tbreak:end);
db.data_GF_sub1=db.data_GF(:,Tbreak_GF:end);
% db.data_sub1=db.data(:,Tbreak:end);

db.data1_sub2=db.data1(:,1:Tbreak-1);
db.data1_GF_sub2=db.data_GF(:,1:Tbreak_GF-1);
% db.data_sub2=db.data(:,1:Tbreak-1);

